use eframe::egui;
use eframe::egui::{Context, FontId};
use eframe::egui::FontFamily::Proportional;
use eframe::egui::TextStyle::{Body, Button, Heading, Monospace, Small};

/// 初始化应用
pub fn init_app(ctx: &Context) {
    load_fonts(ctx);
    configure_text_style(ctx);
}

/// 初始化字体，配置支持中文的字体
pub fn load_fonts(ctx: &Context) {
    let mut fonts = egui::FontDefinitions::default();
    fonts.font_data.insert(
        "my_font".to_owned(),
        egui::FontData::from_static(include_bytes!("../../fonts/simsun.ttc")),
    );
    fonts
        .families
        .entry(egui::FontFamily::Proportional)
        .or_default()
        .insert(0, "my_font".to_owned());

    fonts
        .families
        .entry(egui::FontFamily::Monospace)
        .or_default()
        .push("my_font".to_owned());
    ctx.set_fonts(fonts);
}

/// 配置文字样式
pub fn configure_text_style(ctx: &Context) {
    let mut style = (*ctx.style()).clone();
    style.text_styles = [
        (Heading, FontId::new(30.0, Proportional)),
        (Body, FontId::new(18.0, Proportional)),
        (Monospace, FontId::new(14.0, Proportional)),
        (Button, FontId::new(14.0, Proportional)),
        (Small, FontId::new(10.0, Proportional)),
        (Button, FontId::new(18.0, Proportional)),
    ].into();
    ctx.set_style(style);
}